////////////////////////////////////////////////////////////////////////////////
//(c) Intelliquip, Inc. 2001
////////////////////////////////////////////////////////////////////////////////
//$Log:
// 29   Version 10.0 (Current View)1.28        11/5/2010 1:05:31 PM   Stephen
//      Kish    IDD#6245: Refactoring changes
// 28   Version 10.0 (Current View)1.27        10/19/2010 2:26:32 PM  Stephen
//      Kish    IDD#6245: Refactoring HttpSessions.get and set Attribute to use
//      DAO classes
// 27   Version 10.0 (Current View)1.26        6/22/2005 5:16:12 PM   Scott
//      Frees     added revision flag to show revision history (IDD#4206)
// 26   Version 10.0 (Current View)1.25        4/7/2004 4:01:45 PM    Wayne
//      Hefner    Add CNLWrapper back
// 25   Version 10.0 (Current View)1.24        9/10/2003 4:55:11 PM   Jeff
//      Heigl      IDD#2607: Performance Datasheet's Additional Data page is
//      now implemented.
// 24   Version 10.0 (Current View)1.23        7/14/2003 11:22:03 AM  Jonathan
//      Lutz   IDD #2422: Created new System Data tab for COS page.
// 23   Version 10.0 (Current View)1.22        5/14/2003 4:06:33 PM   Jonathan
//      Lutz   IDD #2049: Product Line Options implemented.
// 22   Version 10.0 (Current View)1.21        4/7/2003 9:21:12 AM    Jonathan
//      Lutz   IDD #2059: Multi-Speed Curves UI implementation.
// 21   Version 10.0 (Current View)1.20        3/24/2003 12:05:43 PM  Jonathan
//      Lutz   IDD #0170: Life Cycle Cost preliminary implementation.
// 20   Version 10.0 (Current View)1.19        3/11/2003 4:44:20 PM   Jeff
//      Heigl      IDD#2039: Intelliquip name change
// 19   Version 10.0 (Current View)1.18        2/24/2003 11:10:54 AM  Jeff
//      Heigl      IDD#1879: equation log deleted
// 18   Version 10.0 (Current View)1.17        12/11/2002 3:55:25 PM  Jeff
//      Heigl      stripURL fixes
// 17   Version 10.0 (Current View)1.16        12/6/2002 4:49:49 PM   Jeff
//      Heigl      revisions to make browser back button work properly
// 16   Version 10.0 (Current View)1.15        12/5/2002 10:32:57 AM  Jeff
//      Heigl      getCurrentScreen() modified for the case where the request
//      object does not have a non-null selectedURL... in this case it will try
//      the session, if that fails too then a return code of -1 is returned.
// 15   Version 10.0 (Current View)1.14        11/13/2002 1:12:41 PM  Wayne
//      Hefner    Stripped parameters off URL to make page matching work
//      correctly
// 14   Version 10.0 (Current View)1.13        7/11/2002 2:09:25 PM   Eddie
//      Carr      RM 7/11/02 2:06:11 PM EDT: Modified to support framed
//      approach for KSB
// 13   Version 10.0 (Current View)1.12        7/11/2002 2:09:24 PM   Eddie
//      Carr      RM 7/11/02 2:06:10 PM EDT: IDD 835 - Regenerate selection for
//      temp Item
// 12   Version 10.0 (Current View)1.11        7/11/2002 2:09:23 PM   Eddie
//      Carr      RM 7/11/02 2:06:09 PM EDT: added some new links to make sso
//      function
// 11   Version 10.0 (Current View)1.10        7/11/2002 2:09:21 PM   Eddie
//      Carr      RM 7/11/02 2:06:07 PM EDT: added code to deal with new
//      constants in ScreenNames
// 10   Version 10.0 (Current View)1.9         7/11/2002 2:09:19 PM   Eddie
//      Carr      RM 7/11/02 2:06:04 PM EDT: IDD 0136
// 9    Version 10.0 (Current View)1.8         7/11/2002 2:09:18 PM   Eddie
//      Carr      RM 7/11/02 2:06:03 PM EDT: Changes for latest KSB demo.
// 8    Version 10.0 (Current View)1.7         7/11/2002 2:09:16 PM   Eddie
//      Carr      RM 7/11/02 2:06:02 PM EDT: Support for web server independent
//      login.
// 7    Version 10.0 (Current View)1.6         7/11/2002 2:09:15 PM   Eddie
//      Carr      RM 7/11/02 2:06:01 PM EDT: Added page alerting user to a
//      session timeout.  Also, did some cleanup.
// 6    Version 10.0 (Current View)1.5         7/11/2002 2:09:14 PM   Eddie
//      Carr      RM 7/11/02 2:06:00 PM EDT: IDD 0049 - Made changes to support
//      showing different start page based on the user login.
// 5    Version 10.0 (Current View)1.4         7/11/2002 2:09:13 PM   Eddie
//      Carr      RM 7/11/02 2:05:59 PM EDT: Changes to support the German
//      performance datasheet page.
// 4    Version 10.0 (Current View)1.3         7/11/2002 2:09:12 PM   Eddie
//      Carr      RM 7/11/02 2:05:58 PM EDT: Fix for Bug 0005 - Added method
//      getCurrentScreen() with a String parameter to allow the UnitsSet.jsp
//      and NavigationFlags.jsp to get the current page.
// 3    Version 10.0 (Current View)1.2         7/11/2002 2:09:11 PM   Eddie
//      Carr      RM 7/11/02 2:05:57 PM EDT: 
// 2    Version 10.0 (Current View)1.1         7/11/2002 2:09:11 PM   Eddie
//      Carr      RM 7/11/02 2:05:56 PM EDT: 
// 1    Version 10.0 (Current View)1.0         7/11/2002 2:09:10 PM   Eddie
//      Carr      RM 7/11/02 2:05:55 PM EDT: 
//$
//$NoKeywords$
////////////////////////////////////////////////////////////////////////////////
package com.intelliquip.hydraulicselection.control.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.intelliquip.hydraulicselection.util.Debug;


/**
 * This file looks at the Request URL and maps the request
 * to the page for the web-templating mechanism.
 */

public class ScreenFlowManager
{
	public ScreenFlowManager()
	{
	}

	public static int getCurrentScreen(HttpServletRequest request)
	{
		String selectedURL = stripURL((String)(request.getParameter("selectedURL")));
		if(selectedURL != null) {
			return ScreenNames.getScreenIDByURL(selectedURL);
		} else {
			return -1;
		}
	}

/*This function is dangerous, because it is not guaranteed to work properly with the browser back button.
Note: to solve back button problem, selectedURL is being set in main.jsp */
	public static int getCurrentScreen(HttpSession session)
	{
		SessionAttributeDAO_Selector dao = new HttpSessionAttributeDAO_Selector(session);
		String selectedURL = stripURL(dao.getSelectedURL());
		if(selectedURL != null) {
			return ScreenNames.getScreenIDByURL(selectedURL);
		} else {
			return -1;
		}
	}

	public static String stripURL(String selectedURL) {
		Debug.println("ScreenFlowManager: stripURL(), before: selectedURL = " + selectedURL);
		if(selectedURL != null) {

			//strip off query string
			int idx = selectedURL.indexOf("?");
			if(idx > -1) {
				selectedURL = selectedURL.substring(0,idx);
			}

			//strip off leading path
			idx = selectedURL.lastIndexOf('/');
			if(idx > -1) {
				selectedURL = selectedURL.substring(idx);
			}
		}

		Debug.println("ScreenFlowManager: stripURL(), after: selectedURL = " + selectedURL);
		return selectedURL;
	}
}

